<template>
    <div class="container">
        <h1>修改密码</h1>
        <input placeholder="用户名" v-model="username"/>
        <input placeholder="原密码" type="password" v-model="oldPwd"/>
        <input placeholder="新密码" type="password" v-model="newPwd"/>
        <button @click="changePwd">修改密码</button>
        <router-link to="/login"  class="router-link">返回登录</router-link>
    </div>
</template>

<script>
import axios from 'axios';
import '../../assets/style.css'


export default {
    data() {
        return {
            username: '',
            oldPwd: '',
            newPwd: ''
        }
    },
    methods: {
        changePwd() {
            axios.post('http://localhost:8080/shopping/login/changePwd', {
                userName: this.username,
                oldPwd: this.oldPwd,
                newPwd: this.newPwd
            }).then(response => {
                if (response.data.code === 200) {
                    this.$router.push('/login')
                } else {
                    this.$message.error(response.data.msg)
                }
            }).catch(error => {
                this.$message.error(error)
            });
        }
    }
}
</script>